
import java.util.ArrayList;
import java.util.Collections;

public class e024 {
    public static void main(String[] args) {
        ArrayList<String> s = permute("0123456789");
        ArrayList<Long> e = new ArrayList<Long>(s.size());
        for (int i = 0; i < s.size(); i++) {
            e.add(Long.parseLong(s.get(i)));
        }
        Collections.sort(e);
        System.out.println(e.get(999999));
    }

    static ArrayList<String> permute(String s) {
        ArrayList<String> permutations = new ArrayList<String>();
        if (s.length() == 0) {
            permutations.add("");
            return permutations;
        }
        char firstChar = s.charAt(0);
        String restOfString = s.substring(1);
        ArrayList<String> words = (ArrayList<String>)permute(restOfString);
        for (String word : words) {
            for (int i = 0; i <= word.length(); i++)
                permutations.add(insertCharAt(word, firstChar, i));
        }
        return permutations;
    }

    static String insertCharAt(String word, char c, int i) {
        String start = word.substring(0, i);
        String end = word.substring(i);
        return start + c + end;
    }
}